home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_06_04 / v6n4050a.txt < prev    next >
Text File  |  1989-09-26  |  960b  |  48 lines

  1. #include <stdio.h>
  2. #include "q2.h"
  3.  
  4.    static qele_type queue[q_MAX]; 
  5.    static int next_in = 0;
  6.    static int next_out = 0;
  7.  
  8.    
  9.  
  10. /* fetch an item from the queue */
  11.  
  12. qele_type q_get()
  13. {
  14.       qele_type rval;
  15.  
  16.       /* first test to see if there is an item */
  17.       if (next_in == next_out) return EMPTY;
  18.       qele_cpy(rval, queue[next_out++]);
  19.       next_out &= q_WRAP;
  20.       return rval;
  21. }
  22.  
  23. /* put an item in the queue */
  24. qele_type q_put(nval)
  25. qele_type nval;
  26. {
  27.       qele_type rval;
  28.  
  29.       /* first check to see if the queue is full */
  30.       if (((next_in + 1) & q_WRAP) == next_out) return FULL;
  31.       qele_cpy(queue[next_in++], nval);
  32.       next_in &= q_WRAP;
  33.       return NORMAL;
  34. }
  35.  
  36. /* compute entries in queue */
  37. int q_bsy()
  38. {
  39.       return ((next_in + q_MAX) - next_out) & q_WRAP ;
  40. }
  41.  
  42. /* compute free entries in queue */
  43. int q_free()
  44. {
  45.       return q_WRAP - (((next_in + q_MAX) - next_out) & q_WRAP);
  46. }
  47.  
  48.